package p270jp.pxv.android.behavior;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import p045be.IllustDetailRecyclerAdapter;
import p270jp.pxv.android.R;
import p451qm.IVariableHeightRecyclerAdapter;
import p639y6.C7301s;

/* renamed from: jp.pxv.android.behavior.IllustDetailBarBehavior */
/* loaded from: classes2.dex */
public class IllustDetailBarBehavior extends ActionBarBehavior {

    /* renamed from: c */
    public View f18884c;

    /* renamed from: d */
    public ImageButton f18885d;

    /* renamed from: e */
    public LinearLayout f18886e;

    /* renamed from: f */
    public TextView f18887f;

    /* renamed from: g */
    public int f18888g;

    /* renamed from: h */
    public int f18889h;

    /* renamed from: i */
    public int f18890i;

    /* renamed from: j */
    public int f18891j;

    /* renamed from: k */
    public boolean f18892k = false;

    /* renamed from: l */
    public int f18893l = 0;

    /* renamed from: m */
    public boolean f18894m = true;

    /* renamed from: n */
    public boolean f18895n = false;

    /* renamed from: o */
    public final ViewTreeObserver.OnScrollChangedListener f18896o = new ViewTreeObserver$OnScrollChangedListenerC4191a();

    /* renamed from: jp.pxv.android.behavior.IllustDetailBarBehavior$a */
    /* loaded from: classes2.dex */
    public class ViewTreeObserver$OnScrollChangedListenerC4191a implements ViewTreeObserver.OnScrollChangedListener {
        public ViewTreeObserver$OnScrollChangedListenerC4191a() {
        }

        @Override // android.view.ViewTreeObserver.OnScrollChangedListener
        public void onScrollChanged() {
            RecyclerView recyclerView = IllustDetailBarBehavior.this.f18882a;
            if (recyclerView != null) {
                int t = IllustDetailBarBehavior.m4637t(recyclerView);
                IllustDetailBarBehavior illustDetailBarBehavior = IllustDetailBarBehavior.this;
                if (illustDetailBarBehavior.f18888g != t) {
                    illustDetailBarBehavior.m4636u(t);
                }
                IllustDetailBarBehavior.this.f18888g = t;
            }
        }
    }

    /* renamed from: jp.pxv.android.behavior.IllustDetailBarBehavior$b */
    /* loaded from: classes2.dex */
    public class View$OnAttachStateChangeListenerC4192b implements View.OnAttachStateChangeListener {
        public View$OnAttachStateChangeListenerC4192b() {
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewAttachedToWindow(View view) {
        }

        @Override // android.view.View.OnAttachStateChangeListener
        public void onViewDetachedFromWindow(View view) {
            if (IllustDetailBarBehavior.this.f18882a.getAdapter() instanceof IllustDetailRecyclerAdapter) {
                ((IllustDetailRecyclerAdapter) IllustDetailBarBehavior.this.f18882a.getAdapter()).f4816F = null;
            }
            IllustDetailBarBehavior.this.f18882a.getViewTreeObserver().removeOnScrollChangedListener(IllustDetailBarBehavior.this.f18896o);
        }
    }

    /* renamed from: jp.pxv.android.behavior.IllustDetailBarBehavior$c */
    /* loaded from: classes2.dex */
    public class C4193c implements Animator.AnimatorListener {
        public C4193c() {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            IllustDetailBarBehavior illustDetailBarBehavior = IllustDetailBarBehavior.this;
            illustDetailBarBehavior.f18895n = false;
            illustDetailBarBehavior.f18884c.setVisibility(4);
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationRepeat(Animator animator) {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            IllustDetailBarBehavior.this.f18887f.setSingleLine(false);
        }
    }

    /* renamed from: jp.pxv.android.behavior.IllustDetailBarBehavior$d */
    /* loaded from: classes2.dex */
    public class C4194d implements Animator.AnimatorListener {
        public C4194d() {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            IllustDetailBarBehavior illustDetailBarBehavior = IllustDetailBarBehavior.this;
            illustDetailBarBehavior.f18895n = false;
            illustDetailBarBehavior.f18887f.setSingleLine(true);
            IllustDetailBarBehavior illustDetailBarBehavior2 = IllustDetailBarBehavior.this;
            illustDetailBarBehavior2.f18884c.setY((float) (illustDetailBarBehavior2.f18882a.getHeight() - IllustDetailBarBehavior.this.f18893l));
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationRepeat(Animator animator) {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            IllustDetailBarBehavior.this.f18884c.setVisibility(0);
        }
    }

    public IllustDetailBarBehavior(Context context) {
        this.f18890i = (int) context.getResources().getDimension(R.dimen.actionbar_space);
        this.f18891j = (int) context.getResources().getDimension(R.dimen.activity_horizontal_margin);
    }

    /* renamed from: t */
    public static int m4637t(RecyclerView recyclerView) {
        RecyclerView.AbstractC0819y H = recyclerView.m10900H(((GridLayoutManager) recyclerView.getLayoutManager()).m10935g1());
        if (H == null) {
            return 0;
        }
        View view = H.itemView;
        RecyclerView.AbstractC0819y N = RecyclerView.m10895N(view);
        int layoutPosition = (N != null ? N.getLayoutPosition() : -1) - 1;
        IVariableHeightRecyclerAdapter dVar = (IVariableHeightRecyclerAdapter) recyclerView.getAdapter();
        int i = 0;
        for (int i2 = 0; i2 <= layoutPosition; i2++) {
            i += dVar.mo2767a(i2);
        }
        return i - view.getTop();
    }

    @Override // p270jp.pxv.android.behavior.ActionBarBehavior
    /* renamed from: s */
    public void mo4638s(CoordinatorLayout coordinatorLayout, View view, int i) {
        this.f18884c = view;
        RecyclerView recyclerView = (RecyclerView) coordinatorLayout.findViewById(R.id.recycler_view);
        this.f18882a = recyclerView;
        recyclerView.getViewTreeObserver().addOnScrollChangedListener(this.f18896o);
        this.f18882a.addOnAttachStateChangeListener(new View$OnAttachStateChangeListenerC4192b());
        if (this.f18882a.getAdapter() instanceof IllustDetailRecyclerAdapter) {
            ((IllustDetailRecyclerAdapter) this.f18882a.getAdapter()).f4816F = new C7301s(this, 12);
        }
        this.f18885d = (ImageButton) view.findViewById(R.id.show_work_caption_button);
        this.f18886e = (LinearLayout) view.findViewById(R.id.overview_title_container);
        this.f18887f = (TextView) view.findViewById(R.id.overview_title_text_view);
        this.f18889h = coordinatorLayout.getHeight() - view.getHeight();
        m4636u(0);
        this.f18892k = true;
        this.f18893l = this.f18884c.getHeight();
    }

    /* renamed from: u */
    public final void m4636u(int i) {
        if (this.f18882a.getAdapter() instanceof IllustDetailRecyclerAdapter) {
            IllustDetailRecyclerAdapter nVar = (IllustDetailRecyclerAdapter) this.f18882a.getAdapter();
            int i2 = 0;
            for (int i3 = 0; i3 < nVar.f4814D; i3++) {
                i2 += nVar.mo2767a(i3);
            }
            int i4 = this.f18890i;
            if (i > (i2 - this.f18889h) + i4) {
                this.f18884c.setY((float) ((i2 + i4) - i));
                if (!this.f18895n && this.f18894m) {
                    this.f18895n = true;
                    this.f18894m = false;
                    this.f18885d.getLeft();
                    this.f18885d.getRight();
                    ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.f18886e, "translationX", (float) this.f18891j);
                    ofFloat.setDuration(200L);
                    ofFloat.addListener(new C4193c());
                    ofFloat.start();
                    return;
                }
                return;
            }
            this.f18884c.setY((float) (this.f18882a.getHeight() - this.f18884c.getHeight()));
            if (!this.f18892k || (!this.f18895n && !this.f18894m)) {
                this.f18895n = true;
                this.f18894m = true;
                ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this.f18886e, "translationX", (float) (-(this.f18885d.getLeft() - this.f18885d.getRight())));
                ofFloat2.setDuration(200L);
                ofFloat2.addListener(new C4194d());
                ofFloat2.start();
            }
        }
    }
}
